using System;
using System.Collections.Generic;
using AutoCodeUI;
using AutoCodeWeProto;
using Batch2D;
using UnityEngine;
using CSUtils;
using U3dComm;
using U3dGame;
using U3dUtils;
using UnityCommon;
using UnityEngine.Rendering.Universal;
using UnityEngine.SceneManagement;

public class U3dHotFixMain {
    const string _tag = "U3dHotFixMain";
    public static string gameName;

    /// <summary>
    /// 游戏初始化入口--热更新入口
    /// </summary>
    public static void Init() {
        try {
            CLogCat.GetInstance().Init(true);
            CScreenResolution.SetOrientation(ScreenOrientation.Portrait);
            AppStart_Comm.Init();
            AppStart_Comm.Init2();
            ArtStart_Comm.Init();
            CBaseInfo.isUseURP = true;
            OpenScene("Assets/Remote/ResourcesAB/Scene/Game01_main.unity");

            URPAddCam(Camera.main, CCanvas.m_canvas.worldCamera);
        } catch(Exception ex) {
            CLog.Ex(_tag, ex);
        }
    }

    public static void OpenScene(string mapName) {
        MainAssetsManager.LoadScene(mapName, LoadSceneMode.Single, delegate {
            Camera.main.backgroundColor = Color.blue.SetColor("1F1A33");
        });
        //var mapGo = MainAssetsManager.LoadGo($"Assets/Remote/ResourcesAB/Scene/{mapName}.prefab");
    }

    public static void URPAddCam(Camera camBase, Camera camAdd) {
        #if URP
        var camData = camBase.GetUniversalAdditionalCameraData();
        camData.renderType = CameraRenderType.Base;
        var cameraStack = camData.cameraStack;

        var ccwData = camAdd.GetUniversalAdditionalCameraData();
        ccwData.renderType = CameraRenderType.Overlay;

        if(cameraStack.Contains(camAdd) == false) {
            cameraStack.Add(camAdd);
        }
        #endif
    }
}
